{extend name="adminblue/base" /}
{block name="resources"/}
<style>
.modal-infp-style{width:90%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.align_left{text-align: left;}
.align_right{text-align: right;}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<!--<tr>-->
		<!--<th width="10%">-->
			<!--<input type="text" id = 'search_text' placeholder="请输入优惠券名称" class="input-common" />-->
			<!--<input type="button" onclick="searchData()" value="搜索" class="btn-common" />-->
		<!--</th>-->
	<!--</tr>-->
</table>
<table class="table-class">
		<colgroup>
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<!--<col style="width: 10%;">-->
		<col style="width: 10%;">
		</colgroup>
	<thead>
		<tr align="center">
			<th class="center">商品名称</th>
			<th class="center">会员名称</th>
			<th class="center">优惠券名称</th>
			<th class="center">类型</th>
			<th class="center">创建时间</th>
			<th class="center">审核状态</th>
			<!--<th class="center">商品活动对象</th>-->
			<th class="center">操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>

<!-- 模态框（Modal） -->
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/Registration/UserList')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';



					html += '<tr align="center">';
					// if (data["data"][i]["coupon_name"] == null || "" == data["data"][i]["coupon_name"]) {
					// 	html += '<td class="align_left">--</td>';
					// } else {
					// 	html += '<td class="align_left">' + data["data"][i]["coupon_name"] + '</td>';
					// }



					html += '<td class="center">' + data["data"][i]["goods_name"] + '</td>';
					html += '<td class="center">' + data["data"][i]["user_name"] + '</td>';
					html += '<td class="center">' + data["data"][i]["coupon_name"] + '</td>';
                    html += '<td class="center">' ;
                    if(data["data"][i]["tuangou_type"]==1){
                        html += '拼团';
                    }
                    html +='</td>';
					html += '<td class="center">' + timeStampTurnTime(data["data"][i]["create_time"])  + '</td>';

					html += '<td class="center">' ;
                    if(data["data"][i]["is_open"]==0){
                        html += '待审核';
					}else if(data["data"][i]["is_open"]==1){
                        html += '审核通过';
					}else if(data["data"][i]["is_open"]==2){
                        html += '审核拒绝';
					}
                    // html +='</td>';
                    // html += '<td class="center">' ;
                    // if(data["data"][i]["goods_type_crowd"]==1){
                    //     html += '全部';
                    // }else if(data["data"][i]["goods_type_crowd"]==2){
                    //     html += '企业内部活动';
                    // }else if(data["data"][i]["goods_type_crowd"]==3){
                    //     html += '外部活动';
                    // }
                    // html +='</td>';

                    html += '<td class="center">' ;
                    if(data["data"][i]["is_open"]==0){
                        html += '<a href="javascript:;" onclick="audit('+data["data"][i]["tuangou_apply_id"]+','+data["data"][i]["coupon_id"]+','+data["data"][i]["uid"]+',1);">【 通过 】</a> &nbsp;|';
                        html += '<a href="javascript:;" onclick="audit('+data["data"][i]["tuangou_apply_id"]+','+data["data"][i]["coupon_id"]+','+data["data"][i]["uid"]+',2);">【 拒接 】</a>';
                    }
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	if(checked) $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().removeClass("selected");
}

function searchData(){
	LoadingInfo(1);
}

function couponTypeInfo(coupon_type_id){
	$("#coupon_info").modal("show");
	$.ajax({
		type:"post",
		url : "{:__URL('ADMIN_MAIN/promotion/getcoupontypeinfo')}",
		data : { "coupon_type_id" : coupon_type_id },
		success : function(data) {
			$("#coupon_name").text(data["coupon_name"]);
			$("#money").text(data["money"]+"元");
			$("#count").text(data["count"]);
			if(data["max_fetch"] == 0){
				$("#max_fetch").text('不限');
			}else{
				$("#max_fetch").text(data["max_fetch"]+"次");
			}
			$("#at_least").text(data["at_least"]+"元");
			$("#time").text(timeStampTurnTime(data["start_time"])+"到"+timeStampTurnTime(data["end_time"]));
		}
	});
}

function deletecouponType(coupon_type_id) {
    $.ajax({
        type: "post",
        url: "{:__URL('ADMIN_MAIN/promotion/delcoupontype')}",
        data: {"coupon_type_id": coupon_type_id},
        dataType: "json",
        success: function (data) {
            if (data["code"] > 0) {
                showMessage('success', data["message"], "{:__URL('ADMIN_MAIN/promotion/coupontypelist')}");
            } else if (data["code"] == -1) {
                showMessage('error', '已被领取的优惠券不可删除！');
            } else {
                showMessage('error', data['message']);
            }
        }
    })
}
function audit(tuangou_apply_id,coupon_id,uid,status){
	$.ajax({
		type:"post",
		url : "{:__URL('ADMIN_MAIN/Registration/audit')}",
		data : {
		    "tuangou_apply_id" : tuangou_apply_id,
		    "coupon_type_id" : coupon_id,
		    "uid" : uid,
			"is_open":status
		},
		dataType : "json",
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"]);
			}else{
				showMessage('error', data['message']);
			}
            LoadingInfo(1);
        }

	})
}
</script>
{/block}